home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gcc / libnix.lha / gnu / lib / libnix / sources.lha / detach / cback12.S < prev    next >
Encoding:
Text File  |  1994-06-11  |  4.3 KB  |  276 lines

  1. | auto-detaching not baserelative startup code for gcc v2.3.3
  2. | (c) by M.Fleischer and G.Nikl Fri May 27 20:35 1994
  3. | No real bugs known
  4.  
  5. | some specific defines
  6.  
  7. _LVOForbid    =    -132
  8. _LVOPermit    =    -138
  9. _LVOAllocMem    =    -198
  10. _LVOFreeMem    =    -210
  11. _LVOAddTail    =    -246
  12. _LVOFindTask    =    -294
  13. _LVOGetMsg    =    -372
  14. _LVOReplyMsg    =    -378
  15. _LVOWaitPort    =    -384
  16. _LVOCloseLibrary =    -414
  17. _LVOOpenLibrary    =    -552
  18.  
  19. _LVOLock    =     -84
  20. _LVOUnlock    =     -90
  21. _LVOCurrentDir    =    -126
  22. _LVOCreateProc    =    -138
  23.  
  24. tc_MemEntry    =      74
  25. pr_MsgPort    =      92
  26. pr_CLI        =     172
  27.  
  28. cli_Module    =      60
  29.  
  30. SHARED_LOCK    =      -2
  31.  
  32. RETURN_OK    =       0
  33. RETURN_FAIL    =      20
  34.  
  35. | public symbols
  36.  
  37.         .globl    ___subexit
  38.         .globl    _geta4
  39.  
  40.         .text
  41.  
  42. | first entry - init some vars, check for cli or wb start
  43.  
  44. start:        movel    a0,d3
  45.  
  46.         movel    sp,_SaveSP
  47.         movel    4:W,a6
  48.         movel    a6,_SysBase
  49.  
  50.         subal    a1,a1
  51.         jsr    a6@(_LVOFindTask:W)
  52.         movel    d0,a3
  53.  
  54.         movel    _cmdLine,d0
  55.         exg    d0,d3
  56.         bnes    fromCLI
  57.  
  58.         tstl    a3@(pr_CLI:W)
  59.         exg    d0,d3
  60.         bne    Detach
  61.  
  62. | wb start - get wbmsg
  63.  
  64. fromWB:        lea    a3@(pr_MsgPort:W),a0
  65.         jsr    a6@(_LVOWaitPort:W)
  66.         lea    a3@(pr_MsgPort:W),a0
  67.         jsr    a6@(_LVOGetMsg:W)
  68.         movel    d0,__WBenchMsg
  69.  
  70. fromCLI:    tstl    _cmdLine
  71.         beqs    skip1
  72.  
  73.         moveq    #RETURN_FAIL,d7
  74.         lea    ___dosname,a1
  75.         moveq    #33,d0
  76.         jsr    a6@(_LVOOpenLibrary:W)
  77.         movel    d0,_DOSBase
  78.         beq    nolib
  79.         movel    d0,a6
  80.         lea    _curDir,a2
  81.         movel    a2@,d1
  82.         jsr    a6@(_LVOCurrentDir:W)
  83.         movel    d0,a2@
  84.  
  85. | call __submain()
  86.  
  87. skip1:        movel    d3,___commandline
  88.         jmp    ___submain
  89.  
  90. | __subexit() entry - get return val, restore stackptr
  91.  
  92. ___subexit:    movel    sp@(4:W),d7
  93.         movel    _SaveSP,sp
  94.  
  95. | cleanup - close lib, reply wbmsg
  96.  
  97.         movel    _SysBase,a6
  98.         tstl    _cmdLine
  99.         beqs    nolib
  100.  
  101.         movel    a6,a5
  102.         movel    _DOSBase,a6
  103.         movel    _curDir,d1
  104.         jsr    a6@(_LVOCurrentDir:W)
  105.         movel    d0,d1
  106.         jsr    a6@(_LVOUnlock:W)
  107.         movel    a6,a1
  108.         movel    a5,a6
  109.         jsr    a6@(_LVOCloseLibrary:W)
  110.  
  111. nolib:        movel    __WBenchMsg,d2
  112.         beqs    todos
  113.         jsr    a6@(_LVOForbid:W)
  114.         movel    d2,a1
  115.         jsr    a6@(_LVOReplyMsg:W)
  116.  
  117. todos:        movel    d7,d0
  118.  
  119. | geta4() doesn´t do anything, but enables you to use
  120. | one source for both code models
  121.  
  122. _geta4:        rts
  123.  
  124. | detach the process from the shell task
  125.  
  126. Detach:        lea    ___dosname,a1
  127.         moveq    #33,d0
  128.         jsr    a6@(_LVOOpenLibrary:W)
  129.  
  130. | need a private DOSBase !!!
  131.  
  132.         movel    d0,d6
  133.         beq    nodos
  134.  
  135.         movel    a3@(pr_CLI:W),a3
  136.         addal    a3,a3
  137.         addal    a3,a3
  138.         lea    a3@(cli_Module:W),a3
  139.  
  140. | length of the commandline
  141.  
  142.         movel    d3,a0
  143.         moveq    #7,d0
  144. arglen:        addql    #1,d0
  145.         cmpb    #10,a0@+
  146.         bnes    arglen
  147.         moveq    #-8,d2
  148.         andl    d0,d2
  149.  
  150. | number of hunks
  151.  
  152.         moveq    #24,d5
  153.         movel    a3@,a0
  154. cntsegs:    addal    a0,a0
  155.         addal    a0,a0
  156.         addql    #8,d5
  157.         movel    a0@,d0
  158.         movel    d0,a0
  159.         bnes    cntsegs
  160.         addl    d2,d5
  161.  
  162. | needed memory for memlist and commandline
  163.  
  164.         movel    d5,d0
  165.         moveq    #1,d1
  166.         swap    d1
  167.         jsr    a6@(_LVOAllocMem:W)
  168.         movel    d0,a2
  169.         movel    a2,d0
  170.         beq    nomem
  171.  
  172. | setup our memlist - first hunks, then cmdLine
  173.  
  174.         lea    a2@(16:W),a1
  175.         movel    a3@,a0
  176. addsegs:    addal    a0,a0
  177.         addal    a0,a0
  178.         movel    a0@-,d0
  179.         movel    a0,a1@+
  180.         movel    d0,a1@+
  181.         addqw    #1,a2@(14:W)
  182.         movel    a0@(4:W),d0
  183.         movel    d0,a0
  184.         bnes    addsegs
  185.  
  186.         lea    a1@(8:W),a0
  187.         movel    a0,a1@+
  188.         movel    d2,a1@+
  189.         addqw    #1,a2@(14:W)
  190.  
  191. | new commandline for later use
  192.  
  193.         movel    a1,_cmdLine
  194.         movel    d3,a0
  195. cpyarg:        moveb    a0@+,a1@
  196.         cmpb    #10,a1@+
  197.         bnes    cpyarg
  198.  
  199. | new currentdir lock for background process
  200.  
  201.         clrl    sp@-
  202.         movel    sp,d1
  203.         moveq    #SHARED_LOCK,d2
  204.         exg    d6,a6
  205.         jsr    a6@(_LVOLock:W)
  206.         exg    d6,a6
  207.         movel    d0,_curDir
  208.         addqw    #4,sp
  209.  
  210. | create process with disabled multitasking !!!
  211.  
  212.         jsr    a6@(_LVOForbid:W)
  213.  
  214.         movel    __procname,d1
  215.         movel    __priority,d2
  216.         movel    a3@,d3
  217.         movel    __stack,d4
  218.         exg    d6,a6
  219.         jsr    a6@(_LVOCreateProc:W)
  220.         exg    d6,a6
  221.         movel    d0,a5
  222.         movel    a5,d0
  223.         beqs    noproc
  224.  
  225. | insert memlist to free all memory at process end
  226.  
  227.         lea    a5@(-pr_MsgPort+tc_MemEntry:W),a0
  228.         movel    a2,a1
  229.         jsr    a6@(_LVOAddTail:W)
  230.  
  231. | clear cli_Module to prevent unloading by the shell
  232.  
  233.         clrl    a3@
  234.  
  235. | reenable multitasking - all done or maybe not ...
  236.  
  237. noproc:        jsr    a6@(_LVOPermit:W)
  238.  
  239. | if (a5 != 0) goto skip;
  240.  
  241.         movel    a5,d0
  242.         bnes    nomem
  243.  
  244. | error creating the process - free lock and memory
  245.  
  246.         movel    _curDir,d1
  247.         exg    d6,a6
  248.         jsr    a6@(_LVOUnlock:W)
  249.         exg    d6,a6
  250.  
  251.         movel    a2,a1
  252.         movel    d5,d0
  253.         jsr    a6@(_LVOFreeMem:W)
  254.  
  255. | close dos.library
  256.  
  257. nomem:        movel    d6,a1
  258.         jsr    a6@(_LVOCloseLibrary:W)
  259.  
  260. | exit graceful
  261.  
  262. nodos:        moveq    #RETURN_OK,d0
  263.         rts
  264.  
  265. | data area
  266.  
  267.         .data
  268.  
  269. .lcomm        _SaveSP,4
  270. .lcomm        _curDir,4
  271. .lcomm        _cmdLine,4
  272. .lcomm        _DOSBase,4
  273. .comm        _SysBase,4
  274. .comm        __WBenchMsg,4
  275. .comm        ___commandline,4
  276.